using Microsoft.EntityFrameworkCore;
using NLog.Web;
using System.Reflection;
using Traceability.App;
using Traceability.Infrastructure;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers(p => 
{
    p.Filters.Add(typeof(MyExceptionFilter));
});
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(p => 
{
    var path = AppDomain.CurrentDomain.BaseDirectory+"Traceability.App.xml";
    p.IncludeXmlComments(path, true);
});


builder.Services.AddDbContext<TraceabilityDbContext>(p => p.UseSqlServer(builder.Configuration.GetConnectionString("DB")));
builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));
builder.Services.AddMediatR(p => p.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
builder.Services.AddAutoMapper(typeof(AutomapperProfile));
builder.Host.UseNLog();

var app = builder.Build();

// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
//    app.UseSwagger();
//    app.UseSwaggerUI();
//}

app.UseSwagger();
app.UseSwaggerUI();

app.UseAuthorization();

app.MapControllers();
app.UseCors(p => p.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());
app.Run();
